package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.api.WemediaControllerApi;
import com.usian.wemedia.service.WemediaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;

@RequestMapping("/wemedia/api/v1")
@RestController
public class WemediaController implements WemediaControllerApi {

    @Autowired
    private WemediaService wemediaService;

    @GetMapping("findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable("name") String name) {
        if(name!=null&& StringUtils.isEmpty(name)){
            WmUser wmUser=wemediaService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name));
            return wmUser;
        }

        return null;
    }

    @PostMapping("save")
    @Override
    public ResponseResult save(@RequestBody WmUser wmUser) {
        wemediaService.save(wmUser);
        return ResponseResult.errorResult(AppHttpCodeEnum.SUCCESS);
    }
}
